home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 22 / 4 / DISK2247.ZIP / CBASE101.ZIP / BTREE101.ZIP / BTSETVBU.C < prev    next >
Text File  |  1990-06-20  |  2KB  |  87 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)btsetvbu.c    1.4 - 90/06/20" */
  5.  
  6. #include <blkio.h>
  7. #include <errno.h>
  8. /*#include <stddef.h>*/
  9.  
  10. /* local headers */
  11. #include "btree_.h"
  12.  
  13. /*man---------------------------------------------------------------------------
  14. NAME
  15.      btsetvbuf - assign buffering to a btree
  16.  
  17. SYNOPSIS
  18.      #include <btree.h>
  19.  
  20.      int btsetvbuf(btp, buf, bufcnt)
  21.      btree_t *btp;
  22.      void *buf;
  23.      size_t bufcnt;
  24.  
  25. DESCRIPTION
  26.      The btsetvbuf function is used to assign buffering to a btree.
  27.      bufcnt specifies the number of btree nodes to be buffered.  If
  28.      bufcnt has a value of zero, the btree will be completely
  29.      unbuffered.  If buf is not the NULL pointer, the storage area it
  30.      points to will be used instead of one automatically allocated for
  31.      buffering.
  32.  
  33.      The size of the storage area needed can be obtained using the
  34.      BTBUFSIZE() macro:
  35.  
  36.           char buf[BTBUFSIZE(M, KEYSIZE, BUFCNT)];
  37.           btsetvbuf(btp, buf, BUFCNT);
  38.  
  39.      where M is the degree of the btree, KEYSIZE is the size of the
  40.      keys int the btree, and BUFCNT is the number of nodes to buffer.
  41.  
  42.      Any previously buffered data is flushed before installing the new
  43.      buffer area, so btsetvbuf may be called more than once.  This
  44.      allows the buffer size to be varied with the file size.
  45.  
  46.      btsetvbuf will fail if one or more of the following is true:
  47.  
  48.      [EINVAL]       btp is not a valid btree.
  49.      [ENOMEM]       Not enough memory is available for the calling
  50.                     process to allocate.
  51.      [BTENOPEN]     btp is not open.
  52.  
  53. SEE ALSO
  54.      btsetbuf, btsync.
  55.  
  56. DIAGNOSTICS
  57.      Upon successful completion, a value of 0 is returned.  Otherwise,
  58.      a value of -1 is returned, and errno set to indicate the error.
  59.  
  60. ------------------------------------------------------------------------------*/
  61. int btsetvbuf(btp, buf, bufcnt)
  62. btree_t *btp;
  63. void *buf;
  64. size_t bufcnt;
  65. {
  66.     /* validate arguments */
  67.     if (!bt_valid(btp)) {
  68.         errno = EINVAL;
  69.         return -1;
  70.     }
  71.  
  72.     /* check if not open */
  73.     if (!(btp->flags & BTOPEN)) {
  74.         errno = BTENOPEN;
  75.         return -1;
  76.     }
  77.  
  78.     /* set buffering */
  79.     if (bsetvbuf(btp->bp, buf, bt_blksize(btp), bufcnt) == -1) {
  80.         BTEPRINT;
  81.         return -1;
  82.     }
  83.  
  84.     errno = 0;
  85.     return 0;
  86. }
  87.